//
//  baseInputSecretField.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/4/13.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class baseInputSecretField: UIView {

    var leftImg:UIImageView?
    var lineImg:UIView?
    var rightImg:UIButton?
    var textField:UITextField?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setDefaultContent()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setDefaultContent() {
        layer.cornerRadius = 5
        backgroundColor = LDGolbalColor.White
        
        
        leftImg = UIImageView.init(image: UIImage.init(named: "密码"))
        lineImg = UIView.init()
        lineImg?.backgroundColor = LDIconColor.LightGray
        rightImg = UIButton.init()
        rightImg?.setImage(UIImage.init(named: "闭眼"), forState: UIControlState.Normal)
        
        rightImg?.bk_whenTapped({ [weak self] in
            
            self?.textField?.secureTextEntry = !(self?.textField?.secureTextEntry)!
            if (self?.textField?.secureTextEntry) == false {
                self?.rightImg?.setImage(UIImage.init(named: "睁眼"), forState: .Normal)
            } else {
                self?.rightImg?.setImage(UIImage.init(named: "闭眼"), forState: .Normal)
            }
            })
        
        textField = UITextField.init()
        textField?.secureTextEntry = true
        
        
        addSubview(leftImg!)
        addSubview(lineImg!)
        addSubview(rightImg!)
        addSubview(textField!)
        
        leftImg?.snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(self)
            make.left.equalTo(LDMargin_H*3)
            make.size.equalTo(CGSizeMake(15, 15))
        })
        lineImg?.snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(self)
            make.left.equalTo((leftImg?.snp_right)!).offset(LDMargin_H)
            make.size.equalTo(CGSizeMake(1, 20))
            
        })
        textField?.snp_makeConstraints(closure: { (make) in
            
            make.centerY.equalTo(self)
            make.left.equalTo((lineImg?.snp_right)!).offset(LDMargin_H)
            make.top.bottom.equalTo(0)
            make.right.equalTo((rightImg?.snp_left)!)
        })
        rightImg?.snp_makeConstraints(closure: { (make) in
            
            make.centerY.equalTo(self)
            make.right.equalTo(-LDMargin_H*3)
            make.size.equalTo(CGSizeMake(15, 15))
        })
    }

}
